Skip to content

full test coverage#289

Open
VitaliiMYKH wants to merge 4 commits into
mate-academy:masterfrom
VitaliiMYKH:calculator
Open

full test coverage#289
VitaliiMYKH wants to merge 4 commits into
mate-academy:masterfrom
VitaliiMYKH:calculator

Conversation

@VitaliiMYKH
Copy link
Copy Markdown

No description provided.

Comment on lines +6 to +12
case '+':
return firstValue + secondValue;
case '-':
return firstValue - secondValue;
case '*':
return firstValue * secondValue;
case '/':
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make constants for operations chars.

Comment on lines +18 to +20
if (secondValue == Double.MIN_VALUE) {
throw new IllegalValueException("can`t resolve operation");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this Exception? Raising with MIN_VALUE is corectly work, as with ZERO.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it return NuN not 0. Look at this screen ->
https://prnt.sc/1s5kqe1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment on lines +13 to +16
@BeforeEach
void setUp() {
calculator = new Calculator();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think will be better use BeforeAll method. It's redundant Initialize "calculator" before each test.

void addTwoPositiveOk() {
double firstValue = 5;
double secondValue = 1;
double actual = calculator.calculate(firstValue, secondValue, '+');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same with chars, initialize constant for '+' and other operations. You can use "refactor -> introduce field" for change it for all class)

double firstValue = -5;
double secondValue = -1;
double actual = calculator.calculate(firstValue, secondValue, '+');
double expected = -6;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this variables to fields, and initialize them in method.

Comment thread pom.xml Outdated
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<version>5.8.0-RC1</version>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RC means Release Candidate, it could be not stable, try to avoid using RC versions

Comment on lines +18 to +20
if (secondValue == Double.MIN_VALUE) {
throw new IllegalValueException("can`t resolve operation");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

}

@Test
void checkOperatorNotOk() {
Copy link
Copy Markdown

@MaliukDaria MaliukDaria Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name our methods based on the pattern <methodUnderTest>_<state>_<expectedBehavior>

Copy link
Copy Markdown

@MaliukDaria MaliukDaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants